	function showNavBar(finished){
		$.get('navbar.html', function(data){
			$("#nav_area").html(data);
			// $("body").append("<script src=\"nav.js\"><\/script>");
			loadNavUserInfo();
			bindNavBtnAction();
			if (finished) {
				finished();
			}
			
		});
	}

	function loadNavUserInfo(){
		$.get('userinfo.do', function(data){
			try{
				var jsonObj = JSON.parse(data);
				if (jsonObj.error == 0) {
					var thisData = jsonObj.data;
					var head_img = 'img/head/' + thisData.head_image + ".jpg";
					$("#nav_head_img").attr("src", head_img);
					$("#nav_nickname").html(thisData.nickname);

					$("#nav_user_menu").show();
					$("#nav_login").hide();
				}else if (jsonObj.error == 220) {
					// window.location.href = "login.html";
					$("#nav_user_menu").hide();
					$("#nav_login").show();

				}else{
					alert(jsonObj.msg);
				}
			}catch(ex){
				alert(ex);
			}
		})
	}

	
	function navLogout(){
		$.get('logout.do', function(data){
			try{
				console.log(data);
				var jsonObj = JSON.parse(data);
				if (jsonObj.error == 0) {
					window.location.href = "login.html";
				}
			}catch(ex){
				console.log(ex);
			}
		})
	}

	

	function goSearch(){
		var kw = $("#nav_search_bar").val();
		if (kw.length == 0) {
			$("#nav_search_bar").focus();
			return;
		}

		window.location.href = "find.html?kw="+escape(kw);
	}

	function bindNavBtnAction(){
		$("#nav_login_btn").click(function(){
			window.location.href = "login.html";
		})
		$("#nav_reg_btn").click(function(){
			window.location.href = "register.html";
		})
		$("#logout_link").click(function(){
			// console.log('logout');
			navLogout();
		})
		$("#nav_search_bar").keydown(function(e){  
			if (e.keyCode == 13) {
				goSearch();
			}
		});
		$("#nav_search_btn").click(function(){
			goSearch();
		})
	}

